import matplotlib.pyplot as plt
import numpy as np
import os
    
def plot_miss_count():
    x_data = ['MID', 'EDF', 'INS', 'SRPT', 'FB', 'THR', 'OPTFB', 'RM', 'SEDF', 'SALL', 'FIFO', 'FEDF']
    ind = np.arange(len(x_data))
    y_data1 = [902.82, 81.36, 31.72, 559.58, 100.42, 100.5, 56.78, 257.34, 58.08, 592.88, 2482.1, 2482.56]
    y_data2 = [907, 87, 35, 572, 108, 108, 66, 259, 68, 603, 2511, 2511]
    w = 0.2
    ax = plt.subplot(111)
    a = ax.bar(ind,y_data1,width=0.2,align='center')
    b = ax.bar(ind+w,y_data2,width=0.2,align='center')
    ax.set_xticks(ind+w)
    ax.set_xticklabels( ('MID', 'EDF', 'INS', 'SRPT', 'FB', 'THR', 'OPTFB', 'RM', 'SEDF', 'SALL', 'FIFO', 'FEDF') )
    plt.legend((a,b),('ave miss','worst miss'))
    plt.autoscale(tight=True)
    plt.title('The average/worst number of jobs that missed their deadlines')
    plt.tight_layout()
    graph_path = os.path.dirname(os.path.abspath(__file__)) + '/graph/'
    if not os.path.isdir(graph_path):
        os.makedirs(graph_path)
    file_name = graph_path + __file__.split('/')[-1].split('.')[0]
    plt.savefig(f"{file_name}.pdf", bbox_inches='tight')
    plt.close()


if __name__ == '__main__':
    plot_miss_count()
        
